<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-inventoryPrice-edit" th:object="${inventoryPrice}">
            <input id="inventoryPriceId" name="inventoryPriceId" th:field="*{inventoryPriceId}"  type="hidden">
			<input id="inventoryId" name="inventoryId" th:field="*{inventoryId}"  type="hidden">
			<input id="recordId" name="recordId" th:field="*{recordId}"  type="hidden">
			<div class="form-group">
				<label class="col-sm-3 control-label">规格名称：</label>
				<div class="col-sm-8">
					<select id="sizeId" name="sizeId" class="form-control" onchange="selectOnChang(this)">
						<option value="">请选择规格</option>
						<option th:each="inventorySize:${inventorySizeList}" th:field="*{sizeId}" th:value="${inventorySize.sizeId}" th:text="${inventorySize.sizeTitle}"></option>
					</select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">规格值：</label>
				<div class="col-sm-8">
					<select id="priceId" name="priceId" th:field="*{priceId}" class="form-control" >
						<option value="">请选择规格</option>
					</select>
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">入库数量：</label>
				<div class="col-sm-8">
					<input id="itemNum" name="itemNum" th:field="*{itemNum}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">价格：</label>
				<div class="col-sm-8">
					<input id="itemSum" name="itemSum" th:field="*{itemSum}" class="form-control" type="text">
				</div>
			</div>
			<div class="form-group">	
				<label class="col-sm-3 control-label">备注：</label>
				<div class="col-sm-8">
					<input id="remark" name="remark" th:field="*{remark}" class="form-control" type="text">
				</div>
			</div>
		</form>
    </div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
		var prefix = ctx + "business/inventoryPrice";
		$("#form-inventoryPrice-edit").validate({
			rules:{
				xxxx:{
					required:true,
				},
			}
		});
		function selectOnChang(obj){
			//获取被选中的option标签选项
			var sizeId = $.form.selectSelects("sizeId");
			$.ajax({
				type: "POST",
				url: ctx + "business/inventorySizePrice/list",
				data: {
					"sizeId": sizeId
				},
				success: function(result) {
					if (result.code == web_status.SUCCESS) {
						let html = `<option value="">请选择规格</option>`;
						result.data.rows.filter(item=>{
							html += `<option value="${item.priceId}">${item.priceInfo}</option>`;
						});
						$("#priceId").html(html);
					}else {
						$.modal.msgError(result.msg);
					}
				}
			});
		}

		
		function submitHandler() {
	        if ($.validate.form()) {
	            $.operate.save(prefix + "/edit", $('#form-inventoryPrice-edit').serialize());
	        }
	    }
	</script>
</body>
</html>
